﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FineAdmin.Common;
using FineAdmin.IRepository;
using FineAdmin.Model;
using Dapper;
using System.Data;
using DapperExtensions.SqlServerExt;

namespace FineAdmin.Repository
{
    public class RushRepository : BaseRepository<RushModel>, IRushRepository
    {
        public IEnumerable<RushModel> GetRushList()
        {
            using (var conn = SqlHelper.SqlConnection())
            {
                string sql = @"SELECT  * FROM Rush ORDER BY SortCode ASC";
                return conn.Query<RushModel>(sql);
            }
        }

        public int InsertBatch(IEnumerable<RushModel> list)
        {
            int result = 0;
            using (var conn = SqlHelper.SqlConnection())
            {
                IDbTransaction transaction = conn.BeginTransaction();
                try
                {
                    
                    if (list != null)
                    {
                        //批量插入
                        conn.InsertBatch<RushModel>(list, transaction);
                    }
                    result = 1;
                    transaction.Commit();
                }
                catch (Exception)
                {
                    result = -1;
                    transaction.Rollback();
                }
            }
            return result;
        }
    }
}